import {useEffect, useState} from 'react'
import axios from 'axios'

export default function usePublish(state = 1) {
  const [dataSource, setdataSource] = useState([])
  console.log('传参', state)
  useEffect(() => {
    axios.get('/userList/getNews').then(res => {
      const {data: {data}} = res
      setdataSource(data)
    })
  }, [])

  // 发布
  const handlePublish = (id) => {
    console.log('handlePublish')
    console.log('handlePublish: ----', id)
    setdataSource(dataSource.filter(item => item.roleId !== id))
  }

  const handleSunset = (id) => {
    console.log('handleSunset')
    console.log('handleSunset: ++++', id)
    setdataSource(dataSource.filter(item => item.roleId !== id))
  }
  // 删除
  const handleDelete = (id) => {
    console.log('handleDelete')
    console.log('handleDelete传入:',  id)
    setdataSource(dataSource.filter(item => item.roleId !== id))
  }

  return {
    dataSource,
    handlePublish,
    handleSunset,
    handleDelete
  }
}
